<?php require_once('../../core/import.php');?>
<?php User::Permission('OBSERVE_ADD'); ?>
<?php
    if($_SERVER['REQUEST_METHOD']=='POST')
    {
        #图片处理
        $Result=Upload::Probe($_FILES['Thumbnail'],Config::UPLOAD_ATTACHMENT_SIZE_IMAGE,Config::UPLOAD_ATTACHMENT_EXT_IMAGE,Config::PATH_UPLOAD_ATTACHMENT_TEMP);

        $FileName='';
        switch($Result['error'])
        {
            case UPLOAD_ERR_OK:
                $FileName=Upload::Execute($_FILES['Thumbnail'],Config::PATH_UPLOAD_ATTACHMENT_TEMP);
            break;
            case UPLOAD_ERR_NO_FILE:                
                exit('{"Number":"1","Description":"请上传缩略图"}');
            break;
            case Upload::UPLOAD_ERR_CUSTOM_EXT:
                exit('{"Number":"2","Description":"缩略图格式不正确，只能是：'.join(',',Upload::$UPLOAD_EXT_IMAGE).'。"}');
            break;
            case Upload::UPLOAD_ERR_CUSTOM_SIZE:
                exit('{"Number":"3","Description":"缩略图大小超过了限制，不能超过：'.Functions::SizeFormat(Config::UPLOAD_ATTACHMENT_SIZE_IMAGE).'。"}');
            break;
            default :
                exit('{"Number":"4","Description":"缩略图上传失败。错误代码：'.$Result['error'].'，错误描述：'.$Result['message'].'。"}');
        }

        #上传数据
        DB::Insert('observe',array
		(
			'Title'=>Functions::FormArgs('Title'),
			'Content'=>Functions::FormArgs('Content',NULL,FALSE),
			'M_IsTop'=>Functions::FormArgs('M_IsTop'),
			'Datetime'=>date('Y-m-d G:i:s'),
           		'Thumbnail'=>$FileName
		));
		echo '{"Number":"0","Description":"发布成功"}';
    }
?>